const Constants = require('../../utils/constants');
const util = require('../../utils/util.js');
const Api = require('../../utils/api.js');
const Rest = require('../../utils/rest');
const Auth = require('../../utils/auth');

Page({
    data: {
        setting: {},
        iconNav: [],//友情链接
    },
    default: {
        background: Api.JIANGQIE_BG_YQ,
        background1: Api.JIANGQIE_BG_YQ,
        title: '请在后台＞蓝精灵插件＞友情设置中配置！',
        title1: '跑马灯内容请在后台＞蓝精灵插件＞友情设置中配置！',
        description: '请在后台＞蓝精灵插件＞友情设置中配置！',
    },
    onLoad: function (options) {
        let that = this;
        this.xieyi()
        //获取友情链接配置
        Rest.get(Api.JIANGQIE_SETTING_HOME).then(res => {
            that.setData({
                iconNav: res.data.icon_na,
            });
        })
       Rest.get(Api.JIANGQIE_SETTING_lb).then(res => {
        util.getshare(that);
        that.setData({
            setting: {
                background: res.data.background ? res.data.background : that.default.background,
                background1: res.data.background1 ? res.data.background1: that.default.background1,
                background_1: res.data.background_1 ? res.data.background_1 : that.default.background_1,
                background_2: res.data.background_2 ? res.data.background_2: that.default.background_2,
                title: res.data.title ? res.data.title : that.default.title,
                title1: res.data.title1 ? res.data.title1 : that.default.title1,
                description: res.data.description ? res.data.description : that.default.description,
                description1: res.data.description1 ? res.data.description1 : that.default.description1,
            }
        });
    })
},
    onShareAppMessage: function () {
        return {
            title: '小程序友情互链。',
            path: 'pages/yqlj/yqlj',
            imageUrl: '',
        }
    },
/*分享朋友圈自定义*/ 
onShareTimeline(res){
    console.log(res)
    return {
      title: '小程序友情互链。',
      path: 'pages/yqlj/yqlj',
      imageUrl:''
    }

  },
  xieyi:function(){
    wx.showModal({
        title: '温馨提示',
        content: '如果您需要与本小程序互换友情链接，请先阅读互换协议~',
        success: function(res) {
            if (res.confirm) {
            console.log('用户点击确定')
            wx.navigateTo({
                url: '../viewhtml/viewhtml?page_id=839',/*此处更换友情链接页面路径 */
            });
            } else if (res.cancel) {
            console.log('用户点击取消')
            }
        }
    })
    
},
    //slide start----
    handlerSlideChange: function (e) {
        this.setData({
            current: e.detail.current
        })
    },
    //tab -- end
    handlerPageClick: function (e) {
        let page_id = e.currentTarget.dataset.page_id;
        wx.navigateTo({
            url: '/pages/viewhtml/viewhtml?page_id=' + page_id,
        })
    },
    handlerIconNavClick: function(e) {
        let link = e.currentTarget.dataset.link;
        this.openLink(link);
    },
    handlerActiveClick: function(e) {
        let link = e.currentTarget.dataset.link;
        this.openLink(link);
    },
    handlerArticleClick: function (e) {
        let post_id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/article/article?post_id=' + post_id
        })
    },
    openLink: function(link) {
        if(link.startsWith('/pages')) {
            wx.navigateTo({
              url: link,
            })
        } else {
            wx.navigateToMiniProgram({
                appId: link,
                fail: res => {   
                } 
            })
        }
    }
})
